package practises;

public class Num4 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        int a = 1;
        Num4 n = new Num4();
        ListNode ret = n.lastListNode(head, 4);
        System.out.println(ret.val);
        int k = 1;
    }
    public ListNode lastListNode(ListNode head, int count) {
        ListNode slow = head;
        ListNode fast = head;
        while(count-- != 0 && fast != null) {
            fast = fast.next;
        }
        if(count != -1) {
            return null;
        }
        while(fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
